package com.lcb.manager.repository;

import com.lcb.manager.entity.Diary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface DiaryRepository extends JpaRepository<Diary, Integer> {

    @Query(value = "select * from diary where person_id = ?1 and year(`date`) = ?2 and month(`date`) = ?3 ",
            countQuery = "select count(*) from diary where person_id = ?1 and year(`date`) = ?2 and month(`date`) = ?3 ",
            nativeQuery = true)
    Page<Diary> findByDateOrderByDateAsc(int id, String year, String month, Pageable pageable);

    Page<Diary> findByPersonIdOrderByDateAsc(int id, Pageable pageable);
}
